// index.js
// 获取应用实例
const app = getApp()
const api = require("../../utils/api")
const getwxphone = require("../../utils/getwxphone")

Page({
  data: {
    index: 0,
    bindzy: !1,
    zy: '请选择专业',
    xueli: ['请选择学历', '本科', '研究生'],
    input_code: "",
    shows: !1,
    viewShowed: false, //显示结果view的状态
    viewShowed1: false, //显示结果view的状态

  },
  // 事件处理函数
  getInputValue(e) {
    var _ = this
    console.log(e.detail.value)
    // var zhuanye = e.detail.value
    _.setData({
      zhuanye: e.detail.value
    })

  },


  onLoad(options) {


    api.load(options)
    var _ = this;
    var phone = wx.getStorageSync('zymlphone')
    
    if (phone) {
      _.setData({
        shows: 1
      })
    }
    console.log(options)
   

  },
  bindPickerChange: function (e) {
    let num = e.detail.value;
    let _ = this;
    console.log('xueli发送选择改变，携带值为', _.data.xueli[num]);
    this.setData({
      index: e.detail.value,
      inputVal: ''
    })

    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=47185&callback=?', //接收url
      data: {
        xl: _.data.xueli[num],
        limits: 200
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zymc)
        }
        console.log(list)
        _.setData({
          zyList: list
        });
      }
    })

  },
  // 键盘抬起事件
  inputTyping: function (e) {
    console.log("input-----", e)
    var value = e.detail.value
    var cursor = e.detail.cursor
    var _ = this;
    var zys = _.data.zys
    if (value == '') {
      _.setData({
        viewShowed: false,
      });
    } else {
      console.log(_.data.xueli[_.data.index])
      var xl
      if (_.data.index != 0) {
        xl = _.data.xueli[_.data.index]
      } else {
        xl = ''
      }
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=47185&callback=?', //接收url
        data: {
          zymc: value,
          xl: xl,
          limits: 200
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          var list = [];
          for (var i in theJson.lists) { //循环写入下来框
            list.push(theJson.lists[i].zymc)
          }
          console.log(list)
          _.setData({
            zyList: list
          });



        }
      })

    }
  },
  // 获取选中推荐列表中的值
  name: function (res) {

    var index = res.currentTarget.dataset.index
    var _ = this;
    console.log(_.data.carList[index]);


    _.setData({
      inputVal: _.data.carList[index],
      viewShowed: false,
    })

  },


  getPhoneNumber(e) {
    var _ = this;
    var flag = _.data.flag;
    if (flag) {
      const info = {
        area: wx.getStorageSync('area'),
        agent: wx.getStorageSync('agent'),
        page: wx.getStorageSync('page'),
        activeId: 21
      }

      getwxphone(e.detail.code, 47185, 'chaxun', info)
        .then(res => {
          console.log(res);
            wx.request({ //发送请求
              url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=47185&callback=?', //接收url
              data: {
                xl: _.data.xueli[_.data.index],
                zymc: _.data.zy,
                limits: 200
              }, //接收参数
              success(res) {
                var jsonStr = res.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                  jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                  var theJson = JSON.parse(jsonStr);
                }
                console.log(theJson)
                if (theJson.status == 1) {
                  _.setData({
                    theList: theJson.lists
                  })
                  console.log(_.data.theList)
                  wx.pageScrollTo({
                    scrollTop: 500,
                    duration: 300
                  })
                } else {
                  wx.showToast({
                    title: theJson.msg,
                    icon: 'none'
                  })
                }
              }
            })
        })
        .catch(err => {
          console.log(err);
        })
    } else {
        wx.showToast({
          title: '请先勾选隐私协议！',            
          icon: 'none'
        })
      }
  },  


  goToNext(e) {
    var _ = this;
    var phone = wx.getStorageSync('zymlphone')
    if (_.data.index == 0) {
      wx.showToast({
        title: '请先选择学历',
        icon: 'none',
        duration: 2000 //持续的时间
      })
      return false
    } else if (_.data.zy == '') {
      wx.showToast({
        title: '请先选择专业',
        icon: 'none',
        duration: 2000 //持续的时间
      })
      return false
    } else {
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=47185&callback=?', //接收url
        data: {
          xl: _.data.xueli[_.data.index],
          zymc: _.data.zy,
          limits: 200
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          if (theJson.status == 1) {
            _.setData({
              theList: theJson.lists
            })
            console.log(_.data.theList)
            wx.pageScrollTo({
              scrollTop: 500,
              duration: 300
            })
          } else {
            wx.showToast({
              title: theJson.msg,
              icon: 'none'
            })
          }

        }
      })
    }




  },
  xz: function (e) {
    var _ = this;
    var flag = e.detail.value[0];
    if (flag == undefined) {
      flag = false
    } else {
      flag = true
    }
    _.setData({
      flag
    })
    console.log(_.data.flag)
  },
  xy: function (e) {
    var _ = this;
    wx.redirectTo({
      url: '../../agreement/agreement',
    })
  },
  choisezy() {
    var that = this;
    if (that.data.index == 0) {
      wx.showToast({
        title: '请先选择学历！',
        icon: 'none'
      })
    } else {
      that.setData({
        bindzy: 1,
      })
    }

  },
  setzy(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zy)
    that.setData({
      zy: e.currentTarget.dataset.zy,
      bindzy: !1
    })
  },
  closeselect() {
    var that = this;
    that.setData({
      bindzy: !1,
    })
  },

  onShow() {
    wx.hideHomeButton();
  }
})